<template>
    <div class ='wrapper-faq' :style="{height: height}">
        <list class="scroller" :style="{height: height}" offset-accuracy="50px" >
            <refresher @refresh="loadingDown"></refresher>
            <cell v-for="item in articles">
                <comment :data="item"></comment>
            </cell> 
            <cell class="cell-button no-order" v-if="articles.length <= 0">
                <image src="bmlocal://assets/acw/wuwangluo.png" class="noOrderImg"></image>
                <text class="noOrderTxt">暂无交流记录</text>
            </cell>
            <loading class="comm-loading" @loading="onloading" :display="showLoading">
                <loading-indicator class="comm-indicator"></loading-indicator>
                <text class="comm-indicator-text">加载中 ...</text>
            </loading> 
        </list>
        <div class="pub-button" @click='pubQuest'>
            <text class='nativeplusfont plus'>&#xe613;</text>
        </div>
    </div>
</template>
<script>
    const modal = weex.requireModule('modal');
    import refresher from '../common/refresh';
    import comment from '../common/question';
    
    export default {
        props: ["height"],
        data () {
            return {
                
                // loadinging: false,
                showLoading: 'hide',
                token: '',
                pageNum: 1,
                pageSize: 10,
                count: 1,
                statusHeight: Number.parseInt(this.statusBarHeight || weex.config.env.statusBarHeight || 40),
                articles:[]
            }
        },
        created(){
            // modal.alert({
            //                     message: this.height,     // 弹窗内容
            //                     okTitle: '确定',            // 确定按钮文字
            //                     title:'标题'                // title
            //                 }, function(){
            //                     // 点击按钮的回调
            //                 })
            //获取数据
            this.getData();
            const vm = this;
            this.$event.on('refreshQuestionStatus',(params) => {
                // params 为触发该事件所传的参数
                console.log(":::::::::接收到的补单返回值1111:::::::::::: " + JSON.stringify(params));
                this.loadingDown();
            });
        },
        components: {  
            'refresher': refresher,
            comment,
        },
        methods: {
            loadingDown() {
                this.pageNum = 1;
                this.getData()
            },
            onloading (event) {
                this.pageNum = this.pageNum + 1;
                console.log("============== :" + this.pageNum);
                // setTimeout(() => {
                //     this.$notice.loading.hide()
                //     this.goods3.push(...this.goods1);
                //     this.showLoading = 'hide'
                // }, 600)
                let page = Math.ceil(this.count/this.pageSize);
                if(this.pageNum <= page) {
                    this.$notice.loading.show();
                    this.showLoading = 'show';
                    this.getData()
                } else {
                    this.$notice.loading.show();
                    this.showLoading = 'show';
                    setTimeout(() => {
                        this.$notice.loading.hide();
                        this.showLoading = 'hide'
                    }, 600)
                    
                }
            },
            getData() {
                //获取石头币明细接口
                let vm = this;
                var userInfo = this.$storage.getSync('UserInfo');

                this.token = userInfo.token;
                this.$fetch({
                    method: 'POST',    // 大写
                    name: 'question.list', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
                    data: {
                        "pageNum": this.pageNum,
                        "pageSize": this.pageSize,
                        "status": 0
                    },
                    header: {
                        'X-TMACW-APP-Token': this.token
                    }
                }).then(resData => {
                    // 成功回调
                    console.log(":::::::::::::::消息列表::::::::::::::::::::::")
                    console.log(resData)

                    if(resData && resData.errno == 0){
                        if(vm.pageNum == 1){
                            console.log("===================1")
                            this.articles = [];
                            
                            // modal.alert({
                            //     message: resData.data,     // 弹窗内容
                            //     okTitle: '确定',            // 确定按钮文字
                            //     title:'标题'                // title
                            // }, function(){
                            //     // 点击按钮的回调
                            // })


                            // resData.data.list.push({
                            //     '201902':[
                            //         {total: "300.00", recordType: "注11册"}
                            //     ]
                            // })
                            resData.data.items.forEach((item, i) => {
                                this.articles.push(item)
                            });
                            vm.count = resData.data.total;
                            // vm.$notice.loading.hide();
                            // vm.showLoading = 'hide'
                        } else {
                            // console.log("===================2")
                            setTimeout(() => {
                                vm.$notice.loading.hide();
                                resData.data.items.forEach((item, i) => {
                                    this.articles.push(item)
                                });
                                vm.showLoading = 'hide'
                            }, 500)
                            
                        }
                    } else if(resData && resData.errno == 501){
                        
                        setTimeout(() => {
                            vm.$notice.loading.hide();
                            vm.showLoading = 'hide'
                        }, 500)
                        vm.backLogin()
                    } else {
                        this.$notice.toast({ message: resData.errmsg})
                    }
                }, error => {
                    // 错误回调
                    setTimeout(() => {
                        vm.$notice.loading.hide();
                        vm.showLoading = 'hide'
                    }, 500)
                    console.log(error)
                    this.$notice.toast({ message: "获取失败, 请重试"})
                })
            },
            pubQuest(){
                this.$router.open({
                    name: 'zst.faq.pub',
                    type: 'PUSH',
                    params: {},
                    // navShow:true,
                    // navTitle:'交流'
                })
            },
            backLogin () {
                this.$storage.setSync('LoginStatus', 'false')
                this.$storage.setSync('UserInfo', {})
                this.$router.open({
                    name: 'acw.home.login',
                    type: 'PUSH',
                    canBack: false,
                })
            }
        }
    }
</script>
<style lang="scss" src='./index.scss'></style>